﻿USE [ShopDB]
GO

/****** Object:  StoredProcedure [dbo].[BasketGetProductsAndQuantities]    Script Date: 04/07/2011 19:33:48 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BasketGetProductsAndQuantities]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[BasketGetProductsAndQuantities]
GO

USE [ShopDB]
GO

/****** Object:  StoredProcedure [dbo].[BasketGetProductsAndQuantities]    Script Date: 04/07/2011 19:33:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Alexander Litivnenko
-- Create date: 2011
-- Description:	Get Products and their Quantities that user basket contains
-- =============================================
CREATE PROCEDURE [dbo].[BasketGetProductsAndQuantities] 	
	@UserName nvarchar(256)
AS
BEGIN
	SELECT  G.ID, G.Brand, G.Model, G.Description, G.Price, G.ImagePath, G.Quantity, B.InBasket
	FROM Goods AS G
		INNER JOIN
			(SELECT ProductID, Quantity AS InBasket 
			FROM Baskets 
			WHERE UserName = @UserName) AS B
		ON G.ID = B.ProductID
END

GO


